using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
using System.IO;
using System.Text;
namespace Scenario.Modeler.Forms
{
	/// <summary>
	/// Summary description for XSLTCheck.
	/// </summary>
	public class XSLTCheck : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label lblError;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public string XML = string.Empty;
		public string XSLT = string.Empty;

		public XSLTCheck()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.lblError = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// lblError
			// 
			this.lblError.Location = new System.Drawing.Point(16, 24);
			this.lblError.Name = "lblError";
			this.lblError.Size = new System.Drawing.Size(568, 472);
			this.lblError.TabIndex = 0;
			this.lblError.Text = "TODO";
			// 
			// XSLTCheck
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
			this.ClientSize = new System.Drawing.Size(608, 528);
			this.Controls.Add(this.lblError);
			this.Name = "XSLTCheck";
			this.Text = "XSLTCheck";
			this.Load += new System.EventHandler(this.XSLTCheck_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void XSLTCheck_Load(object sender, System.EventArgs e)
		{
			try
			{
				//read XML
				TextReader tr1=new StringReader(this.XML);
				XmlTextReader tr11=new XmlTextReader(tr1);
				XPathDocument xPathDocument=new XPathDocument(tr11);
    
				//read XSLT
				/*TextReader tr2=new StringReader(this.XSLT);
				XmlTextReader tr22=new XmlTextReader(tr2);
				*/
				XslTransform xslt = new XslTransform ();
				
				//xslt.Load(tr22);
				xslt.Load(this.XSLT);
    
				//create the output stream
				StringBuilder sb=new StringBuilder();
				TextWriter tw=new StringWriter(sb);

				//xsl.Transform (doc, null, Console.Out);
				xslt.Transform(xPathDocument,null, tw);
    
				//get result
				this.lblError.Text=sb.ToString();
			}
			catch (Exception ex)
			{
				this.lblError.Text = ex.Message;
			}
		}
	}
}
